    <script>
    var username = '{$principal.name}';
    {literal}
    field_formatters.status=function (value, row, index){
    	if(value == 0) {
    		return "待分配";
    	} else if(value == 1) {
    		return "待处理";
    	} else if(value == 2) {
    		return "<font color='blue'>处理中</font>";
    	} else if(value == 3) {
    		return "<font color='green'>已完成</font>";
    	} else if(value == 4) {
    		return "<font color='red'>已取消</font>";
    	}
    }
    field_formatters.business_type=function (value, row, index){
    	if(value == 'rescue') {
    		return "车辆救援";
    	} else {
    		return value;
    	}
    }
    field_formatters.deal_result=function (value, row, index){
    	if(value == 0) {
    		return "待处理";
    	} else if(value == 1) {
    		return "已退回";
    	} else if(value == 2) {
    		return "<font color='green'>处理成功</font>";
    	} else if(value == 3) {
    		return "<font color='red'>已取消</font>";
    	}
    }
    field_formatters.emergency_level=function (value, row, index){
    	if(value == 3) {
    		return "<font color='red'>紧急</font>";
    	} else if(value == 2) {
    		return "中等";
    	} else {
    		return "一般";
    	}
    }
    field_formatters.priority_level=function (value, row, index){
    	if(value == 3) {
    		return "<font color='red'>高</font>";
    	} else if(value == 2) {
    		return "中";
    	} else {
    		return "低";
    	}
    }
    field_formatters.actual_end = function(value,row,index) {
    	if(!value) return;
    	if(value > row.plan_end) {
    		return "<font color='red'>"+value+"</font>";
    	} else {
    		return "<font color='green'>"+value+"</font>";
    	}
    }
    field_formatters.form_action=function (value, row, index){
    	if(row['status'] == 0) {
    		return "<a class='easyui-linkbutton' onclick='assign("+row['task_id']+","+index+")'>分配任务</a>"+
    			" | <a class='easyui-linkbutton' onclick='seize("+row['task_id']+","+index+")'>抢占任务</a>";
    	} else if(row['status'] == 1 && username == row['participant_id']) {
    		var result = "<a onclick='start("+row['task_id']+","+index+")'>开始任务</a>" + 
				" | <a class='easyui-linkbutton' onclick='reassign("+row['task_id']+","+index+")'>重分配任务</a>";
    		if(row['parent_id'] == null && row['allow_split'] == 1) {
    			result = result + " | <a class='easyui-linkbutton' onclick='split("+row['task_id']+","+index+")'>分解任务</a>";
    		}
    		return result;
    	} else if(row['status'] == 2 && username == row['participant_id']) {
    		var result = "<a class='easyui-linkbutton' onclick='commit("+row['task_id']+","+index+")'>处理任务</a>";
    		if(row['parent_id'] == null && row['allow_split'] == 1) {
    			result = result + " | <a class='easyui-linkbutton' onclick='split("+row['task_id']+","+index+")'>分解任务</a>";
    		}
    		return result;
    	}
    }
	events_combobox_onselect.priority_level = function (rec) {
		//
	}
    function assign(task_id, index) {
        getDialog('dlg2').dialog('open').dialog('setTitle','分配任务');
        getForm('dlg2').form('clear');
        getForm('dlg2').attr('action', '/flow/FlowEngine/assign.do');
        getForm('dlg2').attr('dg', 'dg');
        var row = getDatagridRow('dg', index);
        getForm('dlg2').form('load',row);
    }
    function reassign(task_id, index) {
        getDialog('dlg2').dialog('open').dialog('setTitle','分配任务');
        getForm('dlg2').form('clear');
        getForm('dlg2').attr('action', '/flow/FlowEngine/reassign.do');
        getForm('dlg2').attr('dg', 'dg');
        var row = getDatagridRow('dg', index);
        getForm('dlg2').form('load',row);
    }
    function seize(task_id, index) {
    	$('#dg').datagrid('scrollTo', index); //滚动到指定行
    	$('#dg').datagrid('selectRow', index); //选中指定行
    	var params=new Array("task_id");
    	handleOne('/flow/FlowEngine/seize.do?participant_id=admin', params,'dg');
    }
    function start(task_id, index) {
    	$('#dg').datagrid('scrollTo', index); //滚动到指定行
    	$('#dg').datagrid('selectRow', index); //选中指定行
    	var params=new Array("task_id","participant_id");
    	handleOne('/flow/FlowEngine/start.do', params,'dg');
    }
    function split(task_id, index) {
        getDialog('dlg4').dialog('open').dialog('setTitle','分解任务');
        getForm('dlg4').form('clear');
        getForm('dlg4').attr('action', '/flow/FlowEngine/split.do');
        getForm('dlg4').attr('dg', 'dg');
        var row = getDatagridRow('dg', index);
        getForm('dlg4').form('load',row);
    }
    function commit(task_id, index) {
        getDialog('dlg5').dialog('open').dialog('setTitle','提交任务');
        getForm('dlg5').form('clear');
        getForm('dlg5').attr('action', '/flow/FlowEngine/commit.do');
        getForm('dlg5').attr('dg', 'dg');
        var row = getDatagridRow('dg', index);
        getForm('dlg5').form('load',row);
        getFormItem('dlg5', 'to_node_id').combobox('reload', '/flow/NodeService/findNextNodes.do?$value=rows&node_id='+row.node_id);
        getFormItem('dlg5', 'participant_id').textbox('setValue','');
    }
    {/literal}
    </script>